package com.f21.f21assessoria.converter;

import javax.faces.bean.RequestScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.f21.f21assessoria.model.cadastro.Usuario;
import com.f21.f21assessoria.service.UsuarioService;
//@FacesConverter(value = "UsuarioConverter")
@Component("UsuarioConverter")
@RequestScoped
public class UsuarioConverter implements Converter {
	
	@Autowired
	private UsuarioService service;
	
	
	public Object getAsObject(FacesContext context, UIComponent component,
			String value) {
		return service.buscarPorId(new Long(value));
	}

	public String getAsString(FacesContext context, UIComponent component,
			Object value) {
		
		return Long.toString(((Usuario) value).getId());
	}

}
